﻿namespace Huayou.UI.WebControls
{
    using System;
    using System.Collections;
    using System.Reflection;
    using System.Xml;

    public class MenuGroups : Hashtable
    {
        private WebMenu _menu;

        public MenuGroups(WebMenu Menu)
        {
            this._menu = Menu;
        }

        private XmlElement FindMenuGroupElement(XmlElement curGroup, string GroupID)
        {
            XmlElement element = null;
            if ((curGroup.Attributes["ID"] != null) && (curGroup.Attributes["ID"].Value == GroupID))
            {
                return curGroup;
            }
            for (int i = 0; i < curGroup.ChildNodes.Count; i++)
            {
                if (curGroup.ChildNodes[i].HasChildNodes && (element == null))
                {
                    element = this.FindMenuGroupElement((XmlElement) curGroup.ChildNodes[i].ChildNodes[0], GroupID);
                }
            }
            return element;
        }

        public MenuGroup this[string key]
        {
            get
            {
                MenuGroup group;
                try
                {
                    group = new MenuGroup(this.FindMenuGroupElement(this._menu.StartGroupNode, key), this._menu);
                }
                catch
                {
                    throw new Exception("Group '" + key + "' not found.");
                }
                return group;
            }
            set
            {
            }
        }
    }
}

